/**
 * Configuration Validator
 */

import { Config } from '../types';

export interface ValidationResult {
  valid: boolean;
  errors: string[];
}

export function validateConfig(config: Config): ValidationResult {
  const errors: string[] = [];

  // Validate gateway config
  if (!config.gateway) {
    errors.push('Gateway configuration is required');
  } else {
    if (!config.gateway.port || config.gateway.port < 1 || config.gateway.port > 65535) {
      errors.push('Gateway port must be between 1 and 65535');
    }
    if (!config.gateway.host) {
      errors.push('Gateway host is required');
    }
  }

  // Validate logging config  
  if (!config.logging) {
    errors.push('Logging configuration is required');
  } else {
    const validLevels = ['debug', 'info', 'warn', 'error'];
    if (!validLevels.includes(config.logging.level)) {
      errors.push(`Invalid log level: ${config.logging.level}`);
    }
  }

  return {
    valid: errors.length === 0,
    errors
  };
}